<?php
$this->breadcrumbs=array(
	'Orders'=>array('index'),
	$model->orderid,
);

$this->menu=array(
	array('label'=>'List Orders', 'url'=>array('index')),
	array('label'=>'Create Orders', 'url'=>array('create')),
	array('label'=>'Update Orders', 'url'=>array('update', 'id'=>$model->orderid)),
	array('label'=>'Delete Orders', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->orderid),'confirm'=>'Are you sure you want to delete this item?')),
	array('label'=>'Manage Orders', 'url'=>array('admin')),
);
?>

<h1>View Orders #<?php echo $order->orderid; ?></h1>

<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
    <tr>
        <th rowspan="3" class="sized"><img src="<?php echo Yii::app()->theme->baseUrl; ?>/images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
        <th class="topleft"></th>
        <td id="tbl-border-top">&nbsp;</td>
        <th class="topright"></th>
        <th rowspan="3" class="sized"><img src="<?php echo Yii::app()->theme->baseUrl; ?>/images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
    </tr>
    <tr>
        <td id="tbl-border-left"></td>
        <td>
            <!--  start content-table-inner -->
            <div id="content-table-inner">

                <table border="0" width="100%">
                    <tr valign="top">
                        <td>
                            <table border="0" cellpadding="2" cellspacing="3" width="100%">
                                <tr>
                                    <th align="left" width="80">Order ID: </th>
                                    <td  align="left" width="120">#<?php echo $order->orderid; ?></td>
                                </tr>
                                <tr>
                                    <th  align="left" >Order Date: </th>
                                    <td><?php echo date('d-m-Y H:i:s', $order->orderdate); ?></td>
                                </tr>
                                <tr>
                                    <th  align="left">User: </th>
                                    <td><?php echo $order->user->username; ?></td>
                                </tr>                               
                            </table>
                            <br/>
                            <table border="0" cellpadding="2" cellspacing="3" width="100%" class="padded-table">
                                <tr>
                                    <th>Drink Name</th>                                    
                                    <th>Add On Material</th>
                                    <th>Add On Syrup</th>
                                    <th>Total Material Prices</th>
                                    <th>Amount</th>
                                    <th>Total Syrup Prices</th>
                                    <th>Price</th>
                                </tr>
                                <?php
                                    $syrupprice = 0;
                                    $totalPrice = 0;
                                    $toalSyrup = 0;
                                    
                                    foreach ($orderDetail as $detail => $value):                                        
                                        //sum material price
                                        if (intval($value->drinkid) == -1):
                                            $totalMaterial += menuService::getListDrinkMaterial($value->materiallist, true);
                                        else:
                                            $totalMaterial += (menuService::getListDrinkMaterial(menuService::getDrinkRecipe(intval($value->drinkid)), true) * $value->total);
                                        endif;
                                        
                                        echo CHtml::openTag('tr', array('align' => 'center'));
                                        echo CHtml::tag('td', array(), $value->drinkname, true);
                                                                                      
                                        //list material
                                        if ($value->materiallist == '{}' && intval($value->drinkid)  != -1):                                            
                                            echo CHtml::tag('td', array('valign' => 'top'), menuService::getOrangialMaterial(intval($value->drinkid)), true);
                                        else:
                                            echo CHtml::tag('td', array('valign' => 'top'), menuService::getListDrinkMaterial($value->materiallist), true);
                                        endif;
                                        
                                        //list syrup
                                        if ($value->syruplist == '{}' && intval($value->drinkid)  != -1):                                            
                                            echo CHtml::tag('td', array('valign' => 'top'), menuService::getOrangialSyrup(intval($value->drinkid)), true);
                                        else:                                            
                                            echo CHtml::tag('td', array('valign' => 'top'), menuService::getListDrinkSyrup($value->syruplist), true);
                                        endif;

                                        //material price
                                        if (intval($value->drinkid) == -1):
                                            echo CHtml::tag('td', array(), number_format(menuService::getListDrinkMaterial($value->materiallist, true), 0, '', ' '), true);
                                        else:
                                            echo CHtml::tag('td', array(), menuService::getListDrinkMaterial(menuService::getDrinkRecipe(intval($value->drinkid)), true), true);
                                        endif;
                                        
                                        //print total amount if there isn't customer create drink
                                        if (intval($value->drinkid) == -1):
                                            echo CHtml::tag('td', array(), "x 1", true);
                                        else:
                                            echo CHtml::tag('td', array(), " x ".$value->total, true);
                                        endif; 
                                        
                                        //syrup price
                                        if (intval($value->drinkid) == -1):
                                            $syrupPrice = menuService::getListDrinkSyrup($value->syruplist, true);
                                            echo CHtml::tag('td', array(), number_format($syrupPrice, 0, '', ' '), true);
                                        else:                                            
                                            if (is_null($value->syruplist) || $value->syruplist == ''): //default syrup list of drink
                                                $syrupPrice = menuService::getOrangialSyrup($value->drinkid, true);
                                                echo CHtml::tag('td', array(), number_format(menuService::getOrangialSyrup($value->drinkid, true),0, '', ' '), true);
                                            else:   //choose customize syrup
                                                $syrupPrice = menuService::getListDrinkSyrup($value->syruplist, true);
                                                echo CHtml::tag('td', array(), number_format($syrupPrice, 0, '', ' '), true);
                                            endif;
                                        endif;                                        
                                        
                                        $toalSyrup += $syrupPrice;
                                        //final total price 
                                        if (intval($value->drinkid) ==  -1):
                                            echo CHtml::tag('td', array(), number_format(menuService::getListDrinkMaterial($value->materiallist, true) + $syrupPrice, 0, '', ' '),  true);
                                        else:                
                                            $materialPrice = menuService::getListDrinkMaterial(menuService::getDrinkRecipe(intval($value->drinkid)), true) * $value->total;                                            
                                            echo CHtml::tag('td', array(), number_format($materialPrice  + $syrupPrice, 0, '', ' ') ,  true);                                            
                                        endif;                                                
                                        
                                        echo CHtml::closeTag('tr');
                                    endforeach;
                                ?>                               
                                <tr>
                                    <td colspan="7" align="right" style="padding-right: 20px"><span class="total">Total: <?php echo number_format(($toalSyrup+$totalMaterial), 0, '', ' ') . " VNĐ"; ?></span></td>
                                </tr>
                            </table>
                        </td>
                    </tr>                   
                </table>

                <div class="clear"></div>
            </div>
            <!--  end content-table-inner  -->
</td>
<td id="tbl-border-right"></td>
</tr>
<tr>
	<th class="sized bottomleft"></th>
	<td id="tbl-border-bottom">&nbsp;</td>
	<th class="sized bottomright"></th>
</tr>
</table>